package com.kuzufang.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kuzufang.R;

/**
 * Created by songyuanjin on 2017/9/25.
 */

public class SwitchView extends RelativeLayout {
    private RelativeLayout switchItem;
    private ImageView switchImageView;
    private TextView leftShowTextView;
    private TextView rightShowTextView;
    private boolean open = false;

    public SwitchView(Context context) {
        this(context, null);
    }

    public SwitchView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SwitchView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        View view = LayoutInflater.from(context).inflate(R.layout.layout_roommate_switch, this, false);
        switchImageView = (ImageView) view.findViewById(R.id.switch_imageView);
        leftShowTextView = (TextView) view.findViewById(R.id.tv_show1);
        rightShowTextView = (TextView) view.findViewById(R.id.tv_show2);
        switchItem = (RelativeLayout) view.findViewById(R.id.switch_item);

        switchItem.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                open = !open;
                leftShowTextView.setBackgroundResource(open ? R.drawable.selector_primy_color_button_soild_bg : 0);
                rightShowTextView.setBackgroundResource(open ? 0 : R.drawable.selector_primy_color_button_soild_bg);
                leftShowTextView.setTextColor(open ? getResources().getColor(R.color.color_white) : getResources().getColor(R.color.color_a4_grey));
                rightShowTextView.setTextColor(open ? getResources().getColor(R.color.color_a4_grey) : getResources().getColor(R.color.color_white));
            }
        });

        addView(view);
    }

    public void setLeftShowTextView(String textString) {
        leftShowTextView.setText(textString);
    }

    public void setRightShowTextView(String textString) {
        rightShowTextView.setText(textString);
    }
}
